package de.fhaugsburg.games.boardgames.scrabble.application;

import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.Toolkit;
import java.awt.event.ActionEvent;
import java.awt.event.KeyEvent;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.JPanel;
import javax.swing.KeyStroke;

public class MenuTestMacOSX {

	
	
	public static void main(String[] args) {

		/**
		 * the magic two lines: makes JMenuBar appear on to of the screen (MacOSX only)
		 * and sets application title on top-left of the screen
		 * NOTE: on other systems, these properties are simply ignored
		 * NOTE: can also be added from separate properties file
		 * 
		 * More info: http://developer.apple.com/documentation/Java/index.html
		 */
		System.setProperty("apple.laf.useScreenMenuBar", "true");
        System.setProperty("com.apple.mrj.application.apple.menu.about.name", "MacOSX JAVA-App");
        
        /**
         * build new window
         */
		JFrame window = new JFrame();
		window.setTitle("Windowtitle - New Window");
		window.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		window.setSize(320, 150);
		//center on screen
		Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
		window.setLocation(screenSize.width/2 - window.getWidth()/2, screenSize.height/2 - window.getHeight()/2);
		//something on the frame
		JPanel mainStage = new JPanel(new BorderLayout());
		mainStage.add(BorderLayout.NORTH, new JLabel("MacOSX menubar test"));
		window.add(mainStage);
		//a button on the lower-right
		JPanel bottomBar = new JPanel(new BorderLayout());
		bottomBar.add(BorderLayout.EAST, new JButton("Some Button"));
		mainStage.add(BorderLayout.SOUTH, bottomBar);
		
		
		/**
		 * now add the JMenuBar to our application
		 */
		JMenuBar menuBar = new JMenuBar();
	        JMenu fileMenu = new JMenu("File");
	        menuBar.add(fileMenu);
		        
	        	JMenu openMenu = new JMenu("Open");
		        fileMenu.add(openMenu);
			        
		        	JMenuItem menuItem = new JMenuItem("File");
			        openMenu.add(menuItem);
	
			        menuItem = new JMenuItem("URL");
			        openMenu.add(menuItem);
	
		        // menu item with Shortcut <Ctrl> s
		        menuItem = new JMenuItem("Save");
		        menuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_S, ActionEvent.CTRL_MASK));
		        fileMenu.add(menuItem);
	
		        fileMenu.add(menuItem = new JMenuItem("Save as ..."));
	
		        fileMenu.addSeparator();
		        
		        fileMenu.add(menuItem = new JMenuItem("Exit"));
	
	        menuBar.add(new JMenu("Edit"));
	        
	        menuBar.add(new JMenu("View"));
	
	        menuBar.add(new JMenu("Navigate"));
	
	        menuBar.add(new JMenu("Project"));
	
	        menuBar.add(new JMenu("Window"));
	        
	        menuBar.add(new JMenu("Window"));
	
	        menuBar.add(new JMenu("Help"));
        
        /**
         * add the whole JMenuBar to the window, now automatically aligned
         * at the top of the MacOSX desktop 
         */
        window.setJMenuBar(menuBar);
        
        /**
         * show window
         */
        window.setVisible(true);
	}

}
